package com.jsbs.iam.ident.service.impl;

import com.jsbs.iam.ident.dto.ApplyConfigGetDto;
import com.jsbs.iam.ident.dto.ApplyTypeDeleteDto;
import com.jsbs.iam.ident.dto.UserInfoDeleteDto;
import com.jsbs.iam.ident.mapper.UserApiMapper;
import com.jsbs.iam.ident.service.ILoginMangerService;
import com.jsbs.iam.ident.service.UserApiService;
import com.jsbs.iam.ident.vo.ApplyAccountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @BelongsProject: iam
 * @BelongsPackage: com.jsbs.iam.ident.service.impl
 * @Author: WangJiYuan
 * @Description: TODO
 * @Version: 2023-01-16  19:35
 */
@Service
public class UserApiServiceImpl implements UserApiService {

    @Autowired
    private UserApiMapper userApiMapper;

    @Autowired
    private ILoginMangerService iLoginMangerService;

    @Override
    public int deleteAccount(UserInfoDeleteDto deleteDto, HttpServletRequest request, HttpServletResponse response) {
        int i = userApiMapper.deleteAccount(deleteDto);
        //登出  现阶段不强制登出已删除的用户
        //iLoginMangerService.logout(request, response);
        return i;
    }

    @Override
    @Transactional
    public void deleteStrategyRelation(ApplyTypeDeleteDto deleteDto) {
        //删除异常登录策略 iam_exception_login_strategy
        userApiMapper.deleteExceptionLoginStrategy(deleteDto);
        //删除登录策略  iam_login_strategy
        userApiMapper.deleteLoginStrategy(deleteDto);
        //删除多设备策略  iam_multidevice_strategy
        userApiMapper.deleteMultideviceStrategy(deleteDto);
        //删除密码策略  iam_password_strategy
        userApiMapper.deletePasswordStrategy(deleteDto);
    }

    @Override
    public List<ApplyAccountVo> getAccountDataByUser(ApplyConfigGetDto applyConfigGetDto) {
        return userApiMapper.getAccountDataByUser(applyConfigGetDto);
    }
}
